package com.powernode.work.controller;

import com.powernode.commons.utils.ResponseData;
import com.powernode.work.bean.ClueBean;
import com.powernode.work.bean.TranBean;
import com.powernode.work.service.ClueService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("clue")
@Api(tags = "线索维护")
public class ClueController {
    @Autowired
    private ClueService service;


    @GetMapping
    @ApiOperation("分页显示所有的线索")
    public ResponseData page(@RequestParam(required = false,defaultValue = "1") Integer pageNumber,
                             @RequestParam(required = false,defaultValue = "5") Integer pageSize,
                             ClueBean clue){
        return service.page(pageNumber,pageSize,clue);
    }

    @PutMapping
    @ApiOperation("修改线索")
    public ResponseData edit(@RequestBody ClueBean c){
        return service.modify(c);
    }


    @PostMapping
    @ApiOperation("添加线索")
    public ResponseData add(@RequestBody ClueBean c){
        return  service.add(c);
    }

    /**
     * 删除、批量删除
     * @param ids
     * @return
     */
    @DeleteMapping
    public ResponseData del(String ids){
        return service.remove(ids);
    }

    @GetMapping("getById")
    @ApiOperation("根据主键查询线索")
    public ResponseData  getById(String id){
        return service.findById(id);
    }


    @GetMapping("editActivityClue")
    @ApiOperation("重新关联线索和市场活动")
    public ResponseData editActivityClue(String clueId,String activityIds){
        return service.modifyActivityAndClue(clueId,activityIds);
    }

    @PostMapping("convert")
    @ApiOperation("线索转换")
    public ResponseData  convert(String clueId, Boolean createTran,String createBy, @RequestBody TranBean tran){
       /* System.out.println("clueId="+clueId);
        System.out.println("createTran="+createTran);
        System.out.println(tran);*/
        return service.convert(clueId,createTran,createBy,tran);
    }
}
